package com.example.blog.controller.blog;

import com.example.blog.pojo.Result;
import com.example.blog.pojo.Signature;
import com.example.blog.service.SignatureService;
import com.example.blog.util.TokenUtil.GetCookie;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/signatures")
public class SignatureController {

    @Resource
    private SignatureService signatureService;
    //添加个人随笔
    @PostMapping("/add")
    public Result<T> saveSignature(@RequestBody Signature signature, HttpServletRequest request){
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return signatureService.saveSignature(signature,token);
    }
    //查看个人随笔
    @GetMapping("/getUserSignature")
    public Result<List<Signature>> getUserSignature(HttpServletRequest request){
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return signatureService.getUserSignature(token);
    }
    //删除个人随笔
    @DeleteMapping("/delete/{id}")
    public Result<T> deleteSignatureRecord(@PathVariable int id){
        return signatureService.deleteSignatureRecord(id);
    }

}
